package com.lzj.service;

import com.lzj.dao.EmployeeMapper;
import com.lzj.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @autor:lzj
 * @date:2022/2/26
 */
@Service
public class EmployeeServiceImpl implements EmployeeService{
    @Autowired
    private EmployeeMapper employeeMapper;

    public EmployeeServiceImpl(EmployeeMapper employeeMapper) {
        this.employeeMapper = employeeMapper;
    }

    @Override
    public Employee loadEmpByUsername(String username) {
        return employeeMapper.loadEmpByUsername(username);
    }

    @Override
    public int doReg(Employee employee) {
        Employee employee1 = employeeMapper.loadEmpByUsername(employee.getUsername());
        if(employee1!=null){//判断用户名是否存在
            return -1;
        }
        employee.setRole("1");//设定用户级别
        employee.setStatus("0");//设定注册时用户的状态
        return employeeMapper.doReg(employee);
    }

    @Override
    public List<Employee> getAllEmpsByStatus(String status) {
        return employeeMapper.getAllEmpsByStatus(status);
    }

    @Override
    public int approveaccount(int employeeid, String status) {
        return employeeMapper.approveaccount(employeeid,status);
    }

    @Override
    public List<Employee> getAllEmps(Employee employee, int page, int pageSize) {
        return employeeMapper.getAllEmps(employee,page,pageSize);
    }

    @Override
    public Long getTotal(Employee employee) {
        return employeeMapper.getTotal(employee);
    }

    @Override
    public int updateEmp(int id, String status) {
        return employeeMapper.updateEmp(id,status);
    }

    @Override
    public List<Employee> getEmpsByDepId(int depId) {
        return employeeMapper.getEmpsByDepId(depId);
    }

    @Override
    public List<Integer> getEmpsIdByDepName(String employeename) {
        return employeeMapper.getEmpsIdByDepName(employeename);
    }

    @Override
    public List<Employee> getEmpsByEmpId(List<Integer> empById) {
        return employeeMapper.getEmpsByEmpId(empById);
    }

    @Override
    public int updatePassword(String newpassword, int employeeid) {
        return employeeMapper.updatePassword(newpassword,employeeid);
    }

//    @Override
//    public List<Employee> getEmpNameByEmpId(List<Integer> empsId) {
//        return employeeMapper.getEmpNameByEmpId(empsId);
//    }


}
